import Vue from "vue";
import moment from "moment";

Vue.filter("timefmt", (str, style) => {
  return moment(str).format(style);
});

Vue.filter("timefmtS", (str) => {
  let Now = new Date().getTime();
  let timeH = (Now - str) / (1000 * 60 * 60);
  if (timeH * 60 < 1) return "刚刚";
  if (timeH < 1)
    return (
      Math.floor(
        moment
          .duration(moment(Now).valueOf() - moment(str).valueOf())
          .as("minutes")
      ) + "分钟前"
    );
  if (timeH / 24 < 1) return moment(str).format("HH:mm");
  if (timeH / (24 * 365) < 1) return moment(str).format("MM月DD日 HH:mm");
  if (timeH / (24 * 365) > 1) return moment(str).format("YYYY年MM月DD日");
});
